USE [ServerMonitor]
GO
IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[IntToDateTime]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
DROP FUNCTION [dbo].[IntToDateTime]
GO
USE [ServerMonitor]
GO
CREATE FUNCTION [dbo].[IntToDateTime](@Date INT, @Time INT)
RETURNS DATETIME
AS
BEGIN
  IF(@Date IS NULL OR @Date = 0) RETURN(NULL)
  DECLARE @DateStr VARCHAR(8)
  SET @DateStr = REPLICATE('0',8-LEN(CONVERT(VARCHAR(8),@Date)))+ CONVERT(VARCHAR(8),@Date)
  DECLARE @TimeStr VARCHAR(10)
  SET @TimeStr = REPLICATE('0',6-LEN(CONVERT(VARCHAR(6),@Time)))+ CONVERT(VARCHAR(6),@Time)
  SET @TimeStr = SUBSTRING(@TimeStr,1,2) + ':' + SUBSTRING(@TimeStr,3,2) + ':' + SUBSTRING(@TimeStr,5,2)
  RETURN(CONVERT(DATETIME,(@DateStr + ' ' + @TimeStr)))
END

GO


